<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

use think\Request;

/**
 * 定义上传图片类
 * @return \think\response\Json
 */
function upload_image(){
    $file = request()->file('file');
    $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
    if($info){
        // 成功上传后 获取上传信息
        // 输出 jpg
        return json([
            'status'=>1,
            'msg'=>"上传成功",
            'img_path'=> DS.'uploads'.DS.$info->getSaveName()
        ]);
    }else{
        return json([
            'status'=>0,
            'msg'=> $file->getError()
        ]);
    }
};

/**
 * @param $data           弹出的信息
 * @param string $type    弹出框的类型
 * @param string $url     跳转的地址
 */
function alert($data,$type='error',$url=''){
    if(empty($url)==1){
       echo "<script>parent.crm.alert('$data','$type')</script>";die;
    }else{
        echo "<script>parent.crm.alert('$data','$type',function(){parent.location.href='$url';});</script>";die;
    }
}


